<?php

//require './standard/ParserConfiguration.php';

class PageControl {

	public function process() {
		
		//$parser = new ParserConfiguration();
		
		$contexte = new ContextExecution;
		
		Logger::getInstance()->addLogMessage('lancement');
		//Logger::getInstance()->addLogMessage('page:'.$_GET['page']);
		//Logger::getInstance()->writeLogFile();
		$l_page=null;
		if(isset($_GET['page'])){
			$l_page= $_GET['page'];
		} else {
			$l_page='DEFAUT';
		}
		if(isset($_GET['frame'])){
			Logger::getInstance()->addLogMessage('frame:'.$_GET['frame']);
		}
		$classe = ParserConfiguration::getAction($l_page);
		
		//si pas de classe, chargement de la page par defaut
		if($classe==null) {
			//$classe = ParserConfiguration::getAction('LOGIN');
			if($classe==null) {
				die("Configuration incorrecte: $l_page inexistante");
			}
		}
		Logger::getInstance()->addLogMessage('classe:' . $classe->getNom());
		
		if($classe->isPrivee()) {
			$auten = new AuthentificateurStandard();
			$auten->authenticate($contexte);
		}
		
		//$request = new DataRequest;
		
                try{
                    $classe->execute($contexte);
                } catch(TechnicalException $e){
                    echo $e->message;
                    if(is_array($e->tabException)){
                        echo '<table border="1">';
                        echo '<tr><td>ERROR</td></tr>';
                        foreach ($e->tabException as $value) {
                            echo "<tr><td>$value</td></tr>";
                        }
                        echo '</table>';
                        
                        echo '<table border="1">';
                        echo '<tr><td>ERROR</td></tr>';
                        print_r($e->getTrace());
                        foreach ($e->getTrace() as $value) {
                            
                            echo "<tr><td>$value</td></tr>";
                        }
                        echo '</table>';
                        
                    }
                }
		
	
	}

}
?>